
import glob
import re
import string
from pepe.glib import findcoldelimiter_line

def main(f):
    """Guess whether it is flat or report text file
    """
    fh = open(f, 'rb')
    line = fh.readline()
    # skip headers
    line = fh.readline()
    cd1 = findcoldelimiter_line(line)
    line = fh.readline()
    cd2 = findcoldelimiter_line(line)
    fh.close()

    if cd1 <> '' and cd1 == cd2:
        return 'guessed as txt flat'
    else:
        return 'guessed as txt report'

if 0: # test
    for f in glob.glob('*.txt'):
        print f, main(f)
